#!/usr/bin/env python2
from scc.sccdaemon import SCCDaemon
from scc.paths import get_pid_file, get_daemon_socket
from scc.tools import init_logging

import os, argparse

def main():
	init_logging()
	parser = argparse.ArgumentParser()
	parser.add_argument('profile', type=str, nargs='*')
	parser.add_argument('command', type=str, choices=['start', 'stop', 'restart', 'debug'])
	parser.add_argument('--alone', action='store_true', help="prevent scc-daemon from launching osd-daemon and autoswitch-daemon")
	parser.add_argument('--once', action='store_true', help="use with 'stop' to send single SIGTERM without waiting for daemon to exit")
	daemon = SCCDaemon(get_pid_file(), get_daemon_socket())
	args = parser.parse_args()
	daemon.alone = args.alone
	
	profile = " ".join(args.profile)
	if profile:
		daemon.set_default_profile(profile)
		# If no default_profile is set, daemon will try to load last used
		# from config

	if 'start' == args.command:
		daemon.start()
	elif 'stop' == args.command:
		daemon.stop(once = args.once)
	elif 'restart' == args.command:
		daemon.restart()
	elif 'debug' == args.command:
		daemon.debug()


if __name__ == '__main__':
	main()
